package com.df.common.tag;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.df.common.utils.CommonUtils;

import java.lang.reflect.Field;

public class MyQueryWrapper<T> extends QueryWrapper<T> {


    public MyQueryWrapper() {
        super();
    }

    public MyQueryWrapper(T entity) {
        Field[] fields = entity.getClass().getDeclaredFields();
        for (Field field : fields) {
            // 设置可访问，允许访问私有字段
            field.setAccessible(true);
            try {
                Object value = field.get(entity);
                if (value instanceof String && value.equals("")) {
                    field.set(entity, null);
                    System.out.println(field);
                    System.out.println(field.get(entity));
                }
            } catch (Exception ignored) {
            }
        }

        super.setEntity(entity);
        super.initNeed();
    }

    @Override
    public MyQueryWrapper<T> eq(String column, Object val) {
        super.eq(CommonUtils.varIsNotBlank(val), column, val);
        return this;
    }

    @Override
    public MyQueryWrapper<T> like(String column, Object val) {
        super.like(CommonUtils.varIsNotBlank(val), column, val);
        return this;
    }

    @Override
    public MyQueryWrapper<T> between(String column, Object val1, Object val2) {
        super.between(CommonUtils.varIsNotBlank(val1, val2), column, val1, val2);
        return this;
    }

    @Override
    public MyQueryWrapper<T> ge(String column, Object val) {
        super.ge(CommonUtils.varIsNotBlank(val), column, val);
        return this;
    }

    @Override
    public MyQueryWrapper<T> le(String column, Object val) {
        super.le(CommonUtils.varIsNotBlank(val), column, val);
        return this;
    }

    @Override
    public MyQueryWrapper<T> orderByDesc(String column) {
        super.orderByDesc(column);
        return this;
    }

    @Override
    public MyQueryWrapper<T> orderByAsc(String column) {
        super.orderByAsc(column);
        return this;
    }

}